// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"server/components/models/ent/forecast"
	"server/components/models/ent/predicate"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// ForecastDelete is the builder for deleting a Forecast entity.
type ForecastDelete struct {
	config
	hooks    []Hook
	mutation *ForecastMutation
}

// Where appends a list predicates to the ForecastDelete builder.
func (fd *ForecastDelete) Where(ps ...predicate.Forecast) *ForecastDelete {
	fd.mutation.Where(ps...)
	return fd
}

// Exec executes the deletion query and returns how many vertices were deleted.
func (fd *ForecastDelete) Exec(ctx context.Context) (int, error) {
	return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks)
}

// ExecX is like Exec, but panics if an error occurs.
func (fd *ForecastDelete) ExecX(ctx context.Context) int {
	n, err := fd.Exec(ctx)
	if err != nil {
		panic(err)
	}
	return n
}

func (fd *ForecastDelete) sqlExec(ctx context.Context) (int, error) {
	_spec := sqlgraph.NewDeleteSpec(forecast.Table, sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64))
	if ps := fd.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	affected, err := sqlgraph.DeleteNodes(ctx, fd.driver, _spec)
	if err != nil && sqlgraph.IsConstraintError(err) {
		err = &ConstraintError{msg: err.Error(), wrap: err}
	}
	fd.mutation.done = true
	return affected, err
}

// ForecastDeleteOne is the builder for deleting a single Forecast entity.
type ForecastDeleteOne struct {
	fd *ForecastDelete
}

// Where appends a list predicates to the ForecastDelete builder.
func (fdo *ForecastDeleteOne) Where(ps ...predicate.Forecast) *ForecastDeleteOne {
	fdo.fd.mutation.Where(ps...)
	return fdo
}

// Exec executes the deletion query.
func (fdo *ForecastDeleteOne) Exec(ctx context.Context) error {
	n, err := fdo.fd.Exec(ctx)
	switch {
	case err != nil:
		return err
	case n == 0:
		return &NotFoundError{forecast.Label}
	default:
		return nil
	}
}

// ExecX is like Exec, but panics if an error occurs.
func (fdo *ForecastDeleteOne) ExecX(ctx context.Context) {
	if err := fdo.Exec(ctx); err != nil {
		panic(err)
	}
}
